package org.medusa.jsr223;

import java.util.HashMap;
import java.util.Map;

import javax.script.ScriptEngineFactory;
import javax.script.ScriptEngineManager;

import org.medusa.module.Module;

public class Jsr223Manager extends Module {

	private Map<String, Jsr223Engine> inst = new HashMap<String, Jsr223Engine>();
	private ScriptEngineManager factory = new ScriptEngineManager();

	private Jsr223Manager() {
		this.Trace();
	}

	public void Trace() {
		for (ScriptEngineFactory available : this.factory.getEngineFactories()) {
			System.out.println(available.getEngineName());
		}
	}

	public Jsr223Engine GetEngine(String file_ext_name) {
		if (this.inst.get(file_ext_name) == null) {
			this.inst.put(file_ext_name, new Jsr223Engine(this.factory,
					file_ext_name));
		}

		return this.inst.get(file_ext_name);
	}

	@Override
	protected Error event_startup() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	protected Error event_restart() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	protected Error event_shutdown() {
		// TODO Auto-generated method stub
		return null;
	}
}
